<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
   <?php echo $this->breadCrumbs(); ?> :: <?php echo $_['text_orders']?>
  </div>
	<?php if (isset($success)) { ?>
		<div class="success"><?php echo $success; ?></div>
	<?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/order.png" alt="" /><?php echo $_['heading_title']; ?> #<?php echo $order_basket_id;?></h1>
      <div class="buttons"><?php echo $_['text_order_id'];?>: <input type="text" name="input_order_id" size="15">&nbsp;&nbsp;<a onclick="addToBasket()" class="button"><span><?php echo $_['button_add'];?></span></a>
	  |
	  <a onclick="$('#form').submit();" class="button"><span><?php echo $_['button_delete'];?></span></a>
	  |
	  <a onclick="printInvoice()" class="button"><span><?php echo $_['text_print_invoice'];?></span></a>
	  <a onclick="printShippingLabel()" class="button"><span><?php echo $_['text_shipping_label'];?></span></a>
	  <a href="<?php echo UA('sale/order_basket/skus', "order_basket_id=$order_basket_id");?>" target="_blank" class="button"><span><?php echo $_['text_sku'];?></span></a>
	  </div>
    </div>
    <div class="content">
	  <form action="<?php echo UA('sale/order_basket/orders', "order_basket_id=$order_basket_id");?>" method="post" enctype="multipart/form-data" id="form2">
		<input type="hidden" name="order_id" id="order_id" value="0">
	  </form>
      <form action="<?php echo UA('sale/order_basket/orders', "order_basket_id=$order_basket_id");?>" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
			  <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="right"><?php echo $_['text_order_id'];?></td>
              <td class="left"><?php echo $_['text_customer'];?></td>
              <td class="left"><?php echo $_['text_status'];?></td>
              <td class="right"><?php echo $_['text_total'];?></td>
              <td class="left"><?php echo $_['text_date_added'];?></td>
			  <td><?php echo $_['text_payment_method'];?></td>
			  <td><?php echo $_['text_shipping_method'];?></td>
              <td class="right"><?php echo $_['text_action'];?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
			  <td></td>
              <td align="right"><input type="text" name="filter_order_id" value="<?php echo $filter_order_id; ?>" size="4" style="text-align: right;" /></td>
              <td><input type="text" name="filter_customer" value="<?php echo $filter_customer; ?>" size="10"/></td>
              <td><select name="filter_order_status_id">
                <option value=""></option>
				<?php echo form_select_option($order_statuses, $filter_order_status_id, false, 'order_status_id', 'name');?>
                </select></td>			  
              <td></td>
              <td colspan="3"><input type="text" name="filter_date_start" value="<?php echo $filter_date_start; ?>" size="12" class="date" /> - <input type="text" name="filter_date_end" value="<?php echo $filter_date_end; ?>" size="12" class="date" />
				  &nbsp;&nbsp;
			  Model: <input type="text" name="filter_model" value="<?php echo $filter_model; ?>" title="Product Model"></td>
              <td align="right"><a onclick="filter();" class="button"><span><?php echo $_['button_filter'];?></span></a></td>
            </tr>
           </tbody>
           <tbody class="J_tbody_cm">
            <?php if ($orders) { ?>
            <?php foreach ($orders as $order) { ?>
            <tr onmouseover="$(this).addClass('on');" onmouseout="$(this).removeClass('on');"
				data-id="<?php echo $order['order_id'];?>" <?php if ($order['style']) echo 'class="mark_style', $order['style'], '"';?>>
			  <td style="text-align: center;">
                <input type="checkbox" name="selected[]" value="<?php echo $order['order_id']; ?>" />
              </td>
              <td class="right">
              <a class="tipTrigger" href="javascript:;" rel="<?php echo UA('sale/order/product_info'); ?>&order_id=<?php echo $order['order_id']; ?>"><?php echo $order['order_id']; ?></a>
			 
			 <?php if (!empty($order['note'])) {?>
				  <a id="note-<?php echo $order['order_id']; ?>" onclick="showNoteDialog('order', <?php echo $order['order_id'];?>)">
				    <img src="view/image/note.png" />
				  	<span class="none"><?php echo $order['note'];?></span>
				  </a>
				  <?php } else { ?>
				  <a id="note-<?php echo $order['order_id']; ?>" onclick="showNoteDialog('order', <?php echo $order['order_id'];?>)"></a>
			<?php } ?>
			
			  <?php if ($order['invoice_no'] > 0) {?>
			  <br /> <small><?php echo $order['invoice_prefix'].$order['invoice_no']; ?></small>
			  <?php } ?>
              </td>
              <td class="left">
              <a href="mailto:<?php echo $order['email'];?>" title="<?php echo $order['email'];?>"><?php echo $order['customer']; ?></a>
			  <br /><small><?php echo $order['shipping_city']; ?>, <?php echo $order['shipping_country']; ?></small>
              </td>
              <td class="left">
              <a class="tipTrigger" href="javascript:;" rel="<?php echo UA('sale/order/history'); ?>&order_id=<?php echo $order['order_id']; ?>">
			  <?php if($order['status']) { ?>
			  <span class="label" style="background-color:<?php echo $order['status']['color']; ?>;"><?php echo $order['status']['name']?></span>
			  <?php }?>
			  </a>
              </td>
              <td class="right"><?php echo $order['total']; ?></td>
              <td class="left" title="<?php echo $order['date_modified']; ?>"><?php echo $order['date_added']; ?></td>
			  <td><?php echo $order['payment_method']; ?></td>
			  <td><a class="tipTrigger" href="javascript:;" rel="<?php echo UA('sale/order/shipping_history'); ?>&order_id=<?php echo $order['order_id']; ?>">
			  <?php echo $order['shipping_method']; ?>
			  </a>
			  <?php if ($order['shipping_carrier_code']) echo " <b>($order[shipping_carrier_code])</b>";?>
			  </td>
			  <td class="right"><?php foreach ($order['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>" target="_blank"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="18"><?php echo $_['text_no_results'];?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<div id="contextMenu" class="contextMenu">
<ul>
<li id="note"><?php echo $_['cm_add_note']; ?></li>
<li id="style1"><span class="mark_style1"><?php echo $_['cm_mark_style1']; ?></span></li>
<li id="style2"><span class="mark_style2"><?php echo $_['cm_mark_style2']; ?></span></li>
<li id="style3"><span class="mark_style3"><?php echo $_['cm_mark_style3']; ?></span></li>
<li id="style4"><span class="mark_style4"><?php echo $_['cm_mark_style4']; ?></span></li>
<li id="style5"><span class="mark_style5"><?php echo $_['cm_mark_style5']; ?></span></li>
<li id="remove">Remove Style</li>
</ul>
</div>
<script src="<?php echo ROOT;?>static/javascript/jquery/jquery.contextmenu.min.js"></script>
<script type="text/javascript"><!--
function filter() {
	url = '<?php echo UA('sale/order_basket/orders'); ?>&order_basket_id=<?=$order_basket_id?>&filter_reset=1';
	
	var filter_model = $('input[name=\'filter_model\']').attr('value');
	
	if (filter_model) {
		url += '&filter_model=' + encodeURIComponent(filter_model);
	}
	
	var filter_order_id = $('input[name=\'filter_order_id\']').attr('value');
	
	if (filter_order_id) {
		url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
	}
	
	var filter_customer = $('input[name=\'filter_customer\']').attr('value');
	
	if (filter_customer) {
		url += '&filter_customer=' + encodeURIComponent(filter_customer);
	}
	
	var filter_order_status_id = $('select[name=\'filter_order_status_id\']').attr('value');
	
	if (filter_order_status_id) {
		url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
	}
	
	var filter_date_start = $('input[name=\'filter_date_start\']').attr('value');
	
	if (filter_date_start) {
		url += '&filter_date_start=' + encodeURIComponent(filter_date_start);
	}
	
	var filter_date_end = $('input[name=\'filter_date_end\']').attr('value');
	
	if (filter_date_end) {
		url += '&filter_date_end=' + encodeURIComponent(filter_date_end);
	}

	location = url;
}

function addToBasket() {
	var order_id = $('input[name=\'input_order_id\']').attr('value');
	$('#order_id').val(order_id);
	$('#form2').submit();
}

function printInvoice() {
	if ($('input[name*=\'selected\']:checked').length > 0) {
		$('#form').attr('action', '<?php echo UA('sale/order/invoice'); ?>');
	}
	else {
		$('#form').attr('action', '<?php echo UA('sale/order/invoice', "order_basket_id=$order_basket_id"); ?>');
	}
	$('#form').attr('target', '_blank');
	$('#form').submit();
}

function printShippingLabel() {
	if ($('input[name*=\'selected\']:checked').length > 0) {
		$('#form').attr('action', '<?php echo UA('sale/order/shippinglabel'); ?>');
	}
	else {
		$('#form').attr('action', '<?php echo UA('sale/order/shippinglabel', "order_basket_id=$order_basket_id"); ?>');
	}
	$('#form').attr('target', '_blank');
	$('#form').submit();
}
//--></script>  
<script type="text/javascript"><!--
$(document).ready(function() {
	$('.date').datepicker({dateFormat: 'yy-mm-dd'});
	$(".tipTrigger").powerFloat({
		eventType: "click",
		targetMode: "ajax"
	});
	$('.J_tbody_cm tr').contextMenu('contextMenu', {
		bindings: {
			'note': function(tr) {showNoteDialog('order', $(tr).attr('data-id'));},
			'style1': function(tr) {
				$(tr).addClass('mark_style1');
				markStyle('order', $(tr).attr('data-id'), 1);
			},
			'style2': function(tr) {
				$(tr).addClass('mark_style2');
				markStyle('order', $(tr).attr('data-id'), 2);
			},
			'style3': function(tr) {
				$(tr).addClass('mark_style3');
				markStyle('order', $(tr).attr('data-id'), 3);
			},
			'style4': function(tr) {
				$(tr).addClass('mark_style4');
				markStyle('order', $(tr).attr('data-id'), 4);
			},
			'style5': function(tr) {
				$(tr).addClass('mark_style5');
				markStyle('order', $(tr).attr('data-id'), 5);
			},
			'remove': function(tr) {
				$(tr).removeClass();
				markStyle('order', $(tr).attr('data-id'), 0);
			}
		}
	});
});
//--></script> 
<?php echo $footer; ?>